package com.sk.bilibili.model.diy.bottomDialog;

import com.sk.api.annotations.Autowired;
import com.sk.api.tool.BindTool;
import com.sk.bilibili.bean.Collect;
import com.sk.bilibili.bean.Favorites;
import com.sk.bilibili.callBack.RequestCallBack;
import com.sk.bilibili.mapper.CollectMapper;
import com.sk.bilibili.mapper.FavoritesMapper;
import com.sk.bilibili.other.JsonMap;
import com.sk.bilibili.utils.RequestUtils;
import com.sk.bilibili.view.diy.bottomDialog.CollectBottomDialog;

import java.util.List;
import java.util.Map;

public class CollectModel {

    @Autowired
    FavoritesMapper favoritesMapper;
    @Autowired
    CollectMapper collectMapper;
    private CollectBottomDialog view;

    public CollectModel(CollectBottomDialog view) {
        this.view=view;
        BindTool.getInstance().bind(this);
    }

    public void loadFavorites() {
        RequestUtils.process(favoritesMapper.getAll(null, null),
                favorites -> view.loadFavoritesSuccess(favorites));
    }

    public void addCollect(Integer videoSetId, Integer id) {
        JsonMap map=new JsonMap();
        map.put("videoSetId",videoSetId);
        map.put("favoritesId",id);
        RequestUtils.process(collectMapper.add(map),
                collect -> view.addCollectSuccess());
    }

}